from django.conf import settings

from sqtp.models import BaseModel, Case, Environment
from django.db import models


class Plan(BaseModel):
    PLAN_STATUS = (
        (0, '未执行'),
        (1, '执行中'),
        (2, '中断'),
        (3, '已执行'),
    )
    cases = models.ManyToManyField(Case, verbose_name='测试用例')
    executor = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, null=True,
                                 verbose_name='执行者')
    environment = models.ForeignKey(Environment, verbose_name='测试环境', on_delete=models.SET_NULL, null=True)
    name = models.CharField(verbose_name='计划名称', max_length=100, unique=True)
    status = models.SmallIntegerField(verbose_name='计划状态', default=0, choices=PLAN_STATUS)
    exec_counts = models.PositiveSmallIntegerField(default=0, verbose_name='执行次数')


class Report(BaseModel):
    plan = models.ForeignKey(Plan, on_delete=models.DO_NOTHING, related_name='reports', null=True)
    path = models.CharField(verbose_name='报告路径', max_length=500)
    detail = models.TextField(verbose_name='报告详情')
    trigger = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, null=True)
